<template>
    <component :is="currCompName" :stage="stage" :stepStatus="stepStatus" :detail="detail" :disabled="disabled" @save="handleSave" @detailChange="detailChange" />
</template>

<script lang="ts">
import StartProcess from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/StartProcess.vue';
import AuditOpinion from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/AuditOpinion.vue';
import ProductAudit from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/ProductAudit.vue';
import ProductChange from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/ProductChange.vue';
import BasicLine from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/BasicLine.vue';
import SubmitTest from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/SubmitTest.vue';
import RequireTest from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/RequireTest.vue';
import RequireOnline from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/RequireOnline.vue';
import ManagerReview from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/ManagerReview.vue';
import TeamLeaderAduit from '@/views/version/versionDetail/components/RelateProcess/CheckProcess/TeamLeaderAduit.vue';
import VersionRecord from '@/views/version/versionDetail/components/RelateProcess/HistoryRecord/index.vue';
import TestRecord from '@/views/version/versionDetail/components/RelateProcess/HistoryRecord/testHistoryRecord.vue';
import { allStepStatus } from '@/config/commonData';
import { defineComponent, ref, computed } from 'vue';
export default defineComponent({
    name: 'checkProcess',
    components: {
        StartProcess,
        AuditOpinion,
        ProductAudit,
        ProductChange,
        BasicLine,
        SubmitTest,
        RequireTest,
        RequireOnline,
        ManagerReview,
        TeamLeaderAduit,
        VersionRecord,
        TestRecord
    },
    props: {
        detail: { type: Object, default: () => ({}) },
        stepStatus: { type: String, default: '' },
        disabled: { type: Boolean, default: false },
        historyList: { type: Array, default: () => [] },
        showHistoryRecord: { type: Boolean, default: true }
    },
    emits: ['save', 'detailChange'],
    setup(props, { emit }) {
        const form = ref<any>({});
        //获取组件名称
        const currCompName = computed(() => {
            if (props.stepStatus) {
                switch (props.stepStatus) {
                    case 'basicLine':
                        return 'BasicLine';
                    case 'productChange':
                        return 'ProductChange';
                    case 'outSide':
                    case 'requireDev':
                        return 'SubmitTest';
                    case 'requireTest':
                        return 'RequireTest';
                    case 'productManagerReview':
                        return 'ManagerReview';
                    case 'teamLeaderAduit':
                        return 'TeamLeaderAduit';
                    case 'requireOnline':
                        return 'RequireOnline';
                    case 'productAudit':
                    case 'devReview':
                        return 'ProductAudit';
                    default:
                        return 'AuditOpinion';
                }
            } else {
                return 'StartProcess';
            }
        });
        // 当前阶段
        const stage = computed(() => {
            return props.stepStatus ? allStepStatus[props.stepStatus] : '待开始';
        });
        // 是否显示否按钮
        const showNotPassBtn = computed(() => {
            //自研
            if (props.detail.processType === '2') {
                const status = ['productChange'];
                return !status.includes(props.stepStatus);
            } else {
                const status = ['productManagerReview', 'productChange'];
                return !status.includes(props.stepStatus);
            }
        });
        const handleSave = ({ type, query = {} }) => {
            form.value = {
                ...query
            };
            emit('save', type);
        };
        const detailChange = (val: Recordable) => {
            emit('detailChange', val);
        };
        return {
            form,
            currCompName,
            stage,
            showNotPassBtn,
            handleSave,
            detailChange
        };
    }
});
</script>
<style lang="less" scoped>
::v-deep(.btn-group) {
    margin: 0 !important;
    .ant-btn + .ant-btn {
        margin-left: 8px;
    }
}
</style>